<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="新增方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['gainManner']" :trigger-change="true" dictCode="gain_manner" placeholder="请选择新增方式"/>
        </a-form-item>
        <a-form-item label="制具SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolSn', validatorRules.maketoolSn]" placeholder="请输入制具SN"></a-input>
        </a-form-item>
        <a-form-item label="批次数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['batchNum', validatorRules.batchNum]" placeholder="请输入批次数量"></a-input>
        </a-form-item>
        <a-form-item label="制具料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolCode', validatorRules.maketoolCode]" placeholder="请输入制具料号"></a-input>
        </a-form-item>
        <a-form-item label="入库单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inputwareCode']" placeholder="请输入入库单号"></a-input>
        </a-form-item>
        <a-form-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['supplier', validatorRules.supplier]" placeholder="请输入供应商"></a-input>
        </a-form-item>
        <a-form-item label="制具类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolType']" placeholder="请输入制具类型"></a-input>
        </a-form-item>
        <a-form-item label="制具名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolName']" placeholder="请输入制具名称"></a-input>
        </a-form-item>
        <a-form-item label="制具规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolGague']" placeholder="请输入制具规格"></a-input>
        </a-form-item>
        <a-form-item label="最大使用次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maxUsednum']" placeholder="请输入最大使用次数"></a-input>
        </a-form-item>
        <a-form-item label="保养次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maintainNum']" placeholder="请输入保养次数"></a-input>
        </a-form-item>
        <a-form-item label="保养提醒次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['remindNum']" placeholder="请输入保养提醒次数"></a-input>
        </a-form-item>
        <a-form-item label="周期上限" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['cycleLimit']" placeholder="请输入周期上限"></a-input>
        </a-form-item>
        <a-form-item label="保养周期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maintainCycle']" placeholder="请输入保养周期"></a-input>
        </a-form-item>
        <a-form-item label="保养提醒天数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['remindDays']" placeholder="请输入保养提醒天数"></a-input>
        </a-form-item>
        <a-form-item label="累积使用次数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rackupNum']" placeholder="请输入累积使用次数"></a-input>
        </a-form-item>
        <a-form-item label="左上张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['leftupPower']" placeholder="请输入左上张力"></a-input>
        </a-form-item>
        <a-form-item label="右上张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rightupPower']" placeholder="请输入右上张力"></a-input>
        </a-form-item>
        <a-form-item label="中间张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['middlePower']" placeholder="请输入中间张力"></a-input>
        </a-form-item>
        <a-form-item label="左下张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['leftdownPower']" placeholder="请输入左下张力"></a-input>
        </a-form-item>
        <a-form-item label="右下张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rightdownPower']" placeholder="请输入右下张力"></a-input>
        </a-form-item>
        <a-form-item label="张力差异" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['powerGap']" placeholder="请输入张力差异"></a-input>
        </a-form-item>
        <a-form-item label="厚度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['thickDegree']" placeholder="请输入厚度"></a-input>
        </a-form-item>
        <a-form-item label="平整度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['flattenDegree']" placeholder="请输入平整度"></a-input>
        </a-form-item>
        <a-form-item label="库位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wareSite']" placeholder="请输入库位"></a-input>
        </a-form-item>
        <a-form-item label="RoHs标志" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['rohsToken']" :trigger-change="true" dictCode="yn" placeholder="请选择RoHs标志"/>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['notes']" rows="4" placeholder="请输入备注"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"


  export default {
    name: "MesChiefdataMaketoolModal",
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          maketoolSn: {
            rules: [
              { required: true, message: '请输入制具SN!'},
            ]
          },
          batchNum: {
            rules: [
              { required: true, message: '请输入批次数量!'},
            ]
          },
          maketoolCode: {
            rules: [
              { required: true, message: '请输入制具料号!'},
            ]
          },
          supplier: {
            rules: [
              { required: true, message: '请输入供应商!'},
            ]
          },
        },
        url: {
          add: "/chiefdata/mesChiefdataMaketool/add",
          edit: "/chiefdata/mesChiefdataMaketool/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'gainManner','maketoolSn','batchNum','maketoolCode','inputwareCode','supplier','maketoolType','maketoolName','maketoolGague','maxUsednum','maintainNum','remindNum','cycleLimit','maintainCycle','remindDays','rackupNum','leftupPower','rightupPower','middlePower','leftdownPower','rightdownPower','powerGap','thickDegree','flattenDegree','wareSite','rohsToken','notes'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'gainManner','maketoolSn','batchNum','maketoolCode','inputwareCode','supplier','maketoolType','maketoolName','maketoolGague','maxUsednum','maintainNum','remindNum','cycleLimit','maintainCycle','remindDays','rackupNum','leftupPower','rightupPower','middlePower','leftdownPower','rightdownPower','powerGap','thickDegree','flattenDegree','wareSite','rohsToken','notes'))
      },

      
    }
  }
</script>